<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form class="bv-form" id="testForm" role="form" method="post" action="testFile/save">
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                <label for="socre">下载积分&&这个是测试用的:</label>
                <input type="text" class="form-control" name="fileScore" id="socre" placeholder="请输入积分"/>
            </div>
            <div class="form-group">
                <label for="fileTypes">文件类型:</label>
                <select class="form-control" name="fileType" id="fileTypes">

                </select>
            </div>
            <div class="form-group">
                <label>文件状态:</label>
                <select class="form-control" name="fileState" id="fileState">
                </select>
            </div>
        </div>
    </div>
</form>


<!--   //    CDATA全名为character data，指不使用XML解析器解析的文本数据。在标记CDATA下，所有与XML规范冲突的关键字字符串都被XML处理程序一视同仁地当做字符数据看待，CDATA的形式如下：
   //       1、
   // <![CDATA[
   // 文本内容
   //     2、其中文本内容中不能出现字符串“]]>”另外CDATA不能嵌套-->


<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $(function () {
                        /* setTimeout('initTable()', 100);//100毫秒后执行这个方法*/
            $.post("dict/getType", {type: "FILE_TYPE"},
                function (r) {
                    /*  alert("Data Loaded: " + JSON.stringify(r));*/
                    for (var i = 0; i < r.data.length; i++) {
                        /*alert(r.data[i].code);*/
                        /*console.log(r.data[i].code);*/

                        $("#fileTypes", window.top.document).append("<option value=" + r.data[i].value + ">" + r.data[i].text + "</option>");


                    }

                })
            $.post("dict/getType", {type: "FILE_STATE"},
                function (r) {
                    /*  alert("Data Loaded: " + JSON.stringify(r));*/
                    for (var i = 0; i < r.data.length; i++) {
                        /*   alert(r.data[i].code);*/
                        console.log(r.data[i].code);
                        $("#fileState", window.top.document).append("<option value=" + r.data[i].value + ">" + r.data[i].text + "</option>")

                    }
                })
        });


        $('#testForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                socre: {
                    validators: {
                        notEmpty: {
                            message: '积分不能为空'
                        },
                    }
                }
            }
        })

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            $("#btnOk", window.top.document).attr("disabled", true);
       /*     var t = $.fn.zTree.getZTreeObj("roleZtree", window.top.document);*/
           /* var nodes = t.getCheckedNodes(true);
            var treeArray = "";
            for (var i = 0; i < nodes.length; i++) {
                if (i == 0) {
                    treeArray = nodes[i].id
                } else {
                    treeArray = treeArray + "," + nodes[i].id
                }
            }*/
        /*    $("#treeArray", window.top.document).attr("value", treeArray);*/
//获取整个bootstrapValidator 的对象
            var bootstrapValidator = $("#testForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();//对整个表单进行验证
            //isValid()是判断其是否验证通过
            if (bootstrapValidator.isValid()) {
                //1数据提交到后台,响应的方法；2传递到后台的参数，即时提交到数据库的数据
                console.log($("#testForm", window.top.document).attr('action')+"=="+ JSON.stringify($("#testForm", window.top.document).serialize()));
                console.log( $("#testForm", window.top.document).serialize());
                $.post($("#testForm", window.top.document).attr('action'),
                    $("#testForm", window.top.document).serialize(), function (e) {
                    if (e.result) {
                        refreshDoQuery();
                        window.Ewin.alert({message: '增加数据成功!'});
                    } else {
                        window.Ewin.alert({message: '增加数据失败!'});
                    }
                    $("#btnOk", window.top.document).attr("disabled", false);
                })
            } else {
                $("#btnOk", window.top.document).attr("disabled", false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery() {
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for (var i = 0; i < iframes.length; i++) {
                if ($(iframes[i]).css("display") == 'inline') {
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }


    });
    ]]>
</script>
</body>
</html>